import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

class MyCallable implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        //求1~100的和
        int sum=0;
        for (int i = 0; i < 100; i++) {
            sum=sum+i;
        }
        return sum;
    }
}
public class Demo12heima {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1.创建MyCallable的对象(表示多线程要执行的任务)
        MyCallable mc = new MyCallable();
        //2.创建FutureTask的对象(作用管理多线程运行的结果)
        FutureTask<Integer> ft = new FutureTask<>(mc);
        //创建线程对象
        Thread t1= new Thread(ft);
        //启动线程
        t1.start();
        //获取多线程运行的结果
        Integer result=ft.get();
        System.out.println(result);


    }
}
